package cn.ulc.socket.weapp.controller;

import cn.hutool.log.Log;
import cn.hutool.log.LogFactory;
import cn.ulc.common.util.Result;
import cn.ulc.socket.weapp.model.param.CouponExchangeSaveParam;
import cn.ulc.socket.weapp.service.SignServ;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping(value = "/wechat/sign")
public class SignController {
    private static final Log log = LogFactory.get();

    @Autowired
    SignServ signServ;

    @PostMapping("/")
    public Result saveSign(){
        return Result.success(signServ.saveSign());
    }

    @GetMapping("/")
    public Result findIndex(){
        return Result.success(signServ.findIndex());
    }
    @PostMapping("/saveSignFill/{id}")
    public Result saveSignFill(@PathVariable("id") Long id){
        return Result.success(signServ.saveSignFill(id));
    }

    //兑换签到代金券
    @PostMapping("/saveCoupon")
    public Result saveCoupon(@Validated @RequestBody CouponExchangeSaveParam param , BindingResult result){
        if(result.hasErrors()) {
            log.error("兑换代金券",result.getFieldError().getDefaultMessage());
            return Result.fail(result.getFieldError().getDefaultMessage());
        }
        return Result.success(signServ.saveCoupon(param));
    }
}
